<template>
  <div></div>
</template>

<script>
import { getIMDetail } from "@/api/common";
import Storage from "@/plugins/storage";
import { getMemberMsg } from "@/api/login";
import { i18nText } from '@/utils/i18n'

export default {
  data() {
    return {
      Storage,
      IMLink: "",
    };
  },
  methods: {
    // 跳转im客服
    async IMService(id, goodsId, skuId) {

      // 获取访问Token
      let accessToken = Storage.getItem("accessToken");
      await this.getIMDetailMethods();
      const userInfo = await getMemberMsg();
      if (userInfo.success) {
        //携带商品Id,在IM可以发送商品信息
        if(goodsId && skuId){
          window.open(
            this.IMLink + "?token=" + accessToken + "&id=" + (id || this.storeMsg.storeId) + "&goodsId=" + goodsId + "&skuId=" + skuId
          );
        }else{
          // const storeId = process.env.VUE_APP_STORE_ID ? process.env.VUE_APP_STORE_ID : '1720250247973720066'
          window.open(
            // this.IMLink + "?token=" + accessToken + "&id=" + (id || this.storeMsg.storeId)
            this.IMLink + "?token=" + accessToken + "&id=" + process.env.VUE_APP_STORE_ID
          );
        }

      } else {
        this.$Message.error(i18nText('login.pleaseSignInBeforeContactingCustomerService', '请登录后再联系客服'));
        return;
      }
    },
    // 获取im信息
    async getIMDetailMethods() {
      let res = await getIMDetail();
      if (res.success) {
        this.IMLink = res.result;
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
